package com.ligq.h265toupinpush

import org.junit.Assert.assertEquals
import org.junit.Test

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
class ExampleUnitTest {
    @Test
    fun addition_isCorrect() {
        assertEquals(4, 2 + 2)
    }

    @Test
    fun testYuv() {
        val src = arrayOf(
            "01", "02", "03", "04",
            "05", "06", "07", "08",
            "09", "10", "11", "12",
            "13", "14", "15", "16",
        )
        val width = 4
        val height = 4
        val src2d = Array(4) { Array(4) { "" } }
        for (i in 0 until 4) {
            for (j in 0 until 4) {
                src2d[i][j] = src[i * 4 + j]
            }
        }

        val temp = arrayOf(
            src2d[3][0], src2d[2][0], src2d[1][0], src2d[0][0],
            src2d[3][1], src2d[2][1], src2d[1][1], src2d[0][1],
            src2d[3][2], src2d[2][2], src2d[1][2], src2d[0][2],
            src2d[3][3], src2d[2][3], src2d[1][3], src2d[0][3],
        )
        for (i in 0 until 4) {
            for (j in 0 until 4) {
                print("${temp[4 * i + j]}  ")
            }
            println()
        }

        val dest = arrayOfNulls<String>(src.size)
        var k = 0
        for (j in 0 until width) {
            for (i in width - 1 downTo 0) {
                dest[k++] = src[i * width + j]
            }
        }

        println(dest.contentToString())
    }
}